﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JobManage.aspx.cs" Inherits="Quartz.Web.JobManage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="script/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="script/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="script/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="script/ligerUI/js/plugins/ligerToolBar.js" type="text/javascript"></script>
    <script src="script/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
    <script type="text/javascript">
        var grid = null;
        $(document).ready(function () {
            var url = "quartz.aspx";
            var param = [
                { name: "flag", value: "GetJobLists" },
            	{ name: "r", value: Math.random()}];
            grid = $("#maingrid").ligerGrid({
                height: '100%',
                columns: [
                        { display: '任务名称', name: 'jobName', align: 'left', width: 200, minWidth: 100 },
                        { display: '任务组', name: 'jobGroup', width: 200, minWidth: 100 },
                        { display: '任务类型', name: 'jobType', width: 200, minWidth: 100,
                            render: function (item) {
                                var jobtype = item.jobType;
                                if (jobtype.length > 20) jobtype = jobtype.substr(0, 20) + "...";
                                return "<div title='" + item.jobType + "'>" + jobtype + "</div>";
                            }
                        },
                        { display: '状态', name: 'jobStatus', width: 200, minWidth: 100 },
                        { display: '任务描述', name: 'jobDes', width: 200, minWidth: 100 },
                        { display: '查看日志', name: 'viewLog', width: 200, minWidth: 100,
                            render: function (item) {
                                return "<a href=''>" + item.viewLog + "</a>";
                            }
                        }
                        ],
                pageSize: 20,
                rownumbers: true,
                url: url,
                parms: param,
                sortName:'jobName',
                toolbar: { items: [
                        { text: '增加', click: fnAddTask, img: 'script/ligerUI/skins/icons/add.gif' },
                        { line: true },
                        { text: '修改', click: fnEditTask, img: 'script/ligerUI/skins/icons/edit.gif' },
                        { line: true },
                        { text: '删除', click: fnDeleteTask, img: 'script/ligerUI/skins/icons/delete.gif' },
                        { line: true },
                        { text: '查看', click: fnViewTask, img: 'script/ligerUI/skins/icons/attibutes.gif' },
                        { line: true },
                        { text: '立即运行', click: fnExecuteTask, img: 'script/ligerUI/skins/icons/ok.gif' },
                        { line: true },
                        { text: '暂停运行', click: fnPauseTask, img: 'script/ligerUI/skins/icons/graywarn.gif' },
                        { line: true },
                        { text: '恢复运行', click: fnResumeTask, img: 'script/ligerUI/skins/icons/back.gif' }
                        ]
                }
            });
            grid = $("#maingrid").ligerGetGridManager();

        });

        //新增任务
        var fnAddTask = function () {
            parent.addTabs("新增任务", "Quartz/AddJob.aspx?type=add");
        }

        var fnEditTask = function () {
            var grid = $("#maingrid").ligerGetGridManager();
            var row = grid.getSelectedRow();
            parent.addTabs("修改任务", "Quartz/AddJob.aspx?type=edit&jobName=" + row.jobName + "&jobGroupName=" + row.jobGroupName);
        }
        //删除任务
        var fnDeleteTask = function () {
            JobOperate("DeleteJob");
        }
        //查看任务
        var fnViewTask = function () {
            if (grid == null) return;
            var row = grid.getSelectedRow();
            parent.addTabs("查看任务", "Quartz/AddJob.aspx?type=view&jobName=" + row.jobName + "&jobGroupName=" + row.jobGroup + "&jobType=" + row.jobType + "&jobStatus=" + row.jobStatus + "&jobDes=" + row.jobDes + "&r=" + Math.random());
        }
        //立即执行
        var fnExecuteTask = function () {
            JobOperate("ExecuteJob");
        }
        //暂停运行
        var fnPauseTask = function () {
            JobOperate("PauseJob");
        }
        //恢复运行
        var fnResumeTask = function () {
            JobOperate("ResumeJob");
        }

        //操作任务的方法
        function JobOperate(op) {
            if (grid == null) return;
            var row = grid.getSelectedRow();
            var url = "quartz.aspx";
            var param = [
                { name: "flag", value: op },
                { name: "jobName", value: row.jobName },
                { name: "jobGroupName", value: row.jobGroup },
				{ name: "r", value: Math.random()}];
            $.ajax({
                type: 'post',
                url: url,
                data: param,
                dataType: "json",
                success: function (data) {
                    alert(data.Message);
                    grid.loadData(); //刷新数据表
                },
                error: function (data) {
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="maingrid" style="margin:10px; width:100%;height:100%;"></div>
    </form>
</body>
</html>
